package com.lz.kunkun.messageservice.serviceImp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lz.kunkun.messageservice.dao.SysUserMapper;
import com.lz.kunkun.messageservice.model.SysUser;
import com.lz.kunkun.messageservice.service.ISysUserService;
import com.lz.kunkun.messageservice.util.ApplicationException;

/**
 * Hello world!
 *
 */
@Service("sysUserService")
public class SysUserServiceImpl implements ISysUserService 
{
	@Autowired
	SysUserMapper sysUserMapper;

	@Override
	public List<SysUser> getAllSysUsers() {
		List<SysUser> list=sysUserMapper.getAllSysUsers();
		return null==list?new ArrayList<SysUser>():list;
	}

	@Override
	public SysUser login(String userName, String password) {
		return sysUserMapper.login(userName,password);
	}

	@Override
	public int updateUserByUserId(SysUser user) {
		if(user.getName()==null||user.getName().equals("")) {
			throw new ApplicationException(401, "用户名不能为空！");
		}
		return sysUserMapper.updateUserByUserId(user.getUserId(),user.getName(),user.getPhoneNumber(),user.getPassword(),user.getLoginName(),user.getEmail(),user.getSex(),user.getIdCard(),user.getAddress(),user.getAge(),user.getEnable(),user.getUserType(),user.getAmount());
	}

	@Override
	public void updateUserAmount(Integer userId, Integer amount) {
		// TODO Auto-generated method stub
		sysUserMapper.updateUserAmount(userId, amount);
	}

	@Override
	public SysUser getUserById(Integer userId) {
		// TODO Auto-generated method stub
		return sysUserMapper.getUserById(userId);
	}

}
